<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var maxScoreIndices = function (nums) {
      let max = 0, score = 0, res = [0]
      for (let i = 0; i <= nums.length; i++) {
        score = nums[i] === 0 ? score + 1 : score - 1
        if (score === max) {
          res.push(i + 1)
        } else if (score > max) {
          max = score
          res = [i + 1]
        }
      }
      return res
    };
    console.log(maxScoreIndices(nums = [0, 0, 1, 0]))
  </script>
</body>

</html>